package com.woniuxy.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ：CuiYC
 * @description：
 * @date ：Created in 2025/3/7 16:40
 * @modified By：
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private T data;
    private String msg;

    /**
     * 封装两种方法。一个是成功方法，一个是失败方法
     */
    public static <T> ResponseData<T> ok(){
        return new ResponseData<>(ResponseEnum.SUCCESS.getCode(),
                null,ResponseEnum.SUCCESS.getMsg());
    }

    //查询的成功方法
    public static <T> ResponseData<T> ok(T data){
        return new ResponseData<>(ResponseEnum.SUCCESS.getCode(),
                data,ResponseEnum.SUCCESS.getMsg());
    }

    public static <T> ResponseData<T> fail(ResponseEnum responseEnum) {
        return new ResponseData<>(responseEnum.getCode(),
                null, responseEnum.getMsg());
    }
}
